package com.medicine.hbp.adapter;


import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.TextView;

import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.mob.findParentinfoVo;
import com.medicine.hbp.R;

public class FragmentList04 extends MyBaseAdapter {
	public int i = 0;
	public Handler handler;
	public FragmentList04(Activity activity,Handler handler) {
		this.activity = activity;
		this.handler = handler;
	}

	@Override
	public View getView(final int position, View arg1, ViewGroup arg2) {
		final findParentinfoVo vo=(findParentinfoVo) getItem(position);
		TextView view = new TextView(activity);
		view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, dip2px(activity, 45)));
		view.setGravity(Gravity.CENTER);
		if(i ==position){
			view.setBackgroundResource(R.color.white);
		}else{
			view.setBackgroundResource(R.color.transparent);
		}
		if(vo!=null){
			view.setText(vo.laberParentName);
			view.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					i = position;
					Message msg=new Message();
					msg.arg1=vo.laberParentId;
					handler.sendMessage(msg);
					notifyDataSetChanged();
				}
			});
		}
		return view;
	}
	public static int dip2px(Context context, float dipValue){ 
        final float scale = context.getResources().getDisplayMetrics().density; 
        return (int)(dipValue * scale + 0.5f); 
} 

public static int px2dip(Context context, float pxValue){ 
        final float scale = context.getResources().getDisplayMetrics().density; 
        return (int)(pxValue / scale + 0.5f); 
}
}
